package leetcode.other;

import datastructure.list.ArrayList;
import datastructure.list.DuCircleLinkedList2;
import datastructure.list.List;

/**
 * DESCRIPTION:
 * Author: ammar
 * Date:   2021/12/13
 * Time:   下午6:29
 */
public class 约瑟夫问题 {

    public static void main(String[] args) {
        Integer[] items = {1, 2, 3, 4, 5, 6, 7, 8};
        System.out.println(JosephCircle(items));
    }

    public static List<Integer> JosephCircle(Integer[] items) {
        DuCircleLinkedList2<Integer> list = new DuCircleLinkedList2<>();
        for (Integer item : items) {
            list.add(item);
        }
        List<Integer> integerList = new ArrayList<>();
        list.reset();
        while (!list.isEmpty()) {
            list.next();
            list.next();
            Integer current = list.removeCurrent();
            integerList.add(current);
        }
        return integerList;
    }
}
